package main;
import java.util.Arrays;
import java.util.*;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	
	public int compareTo(PersonSortable o){
		if(name.compareTo(o.name)==0){
			if(age==o.age)
			return 0;
			else return age-o.age;
			
		}
		return name.compareTo(o.name);
		
		
		
	}
	
	public PersonSortable(String name,int age) {
		this.name = name;
		this.age=age;
		
	}
	@Override
	public String toString() {
		return name + "-" + age;
	}
	
	
}

public class main2 {
	

	
		public static void main(String[] args) {
			Scanner sc=new Scanner(System.in);
			int n=Integer.parseInt(sc.nextLine());
			String ss[]=new String[n];
			
			PersonSortable[] st = new PersonSortable[n];
			for(int i=0;i<n;i++){
				ss[i]=sc.nextLine();
				String[] s=ss[i].split(" ");
				int a=Integer.parseInt(s[1]);
				st[i]=new PersonSortable(s[0],a);
				
			}
			
			Arrays.sort(st);
			for(PersonSortable e:st){
				System.out.println(e);

				
			}
			System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
		}}
